clear all
close all

%root = "/home/kamil/magisterka/workspace/mgr_tests/Debug";
root="/media/d/mgr_wyniki";
%resultsDir = "00_test_results";
%resultsDir = "01_y_ABC_b_ABC.sh_results"
%resultsDir="02_y_none_b_ABC.sh_results"
%resultsDir="03_y_A_b_ABC.sh_results"
resultsDir="04_y_B_b_ABC.sh_results"
%resultsDir="05_y_C_b_ABC.sh_results"
%resultsDir="06_y_AB_b_ABC.sh_results"
%resultsDir="07_y_AC_b_ABC.sh_results"
%resultsDir="08_y_BC_b_ABC.sh_results"
%resultsDir="11_y_none_b_none.sh_results"

dirName = [root "/" resultsDir];


robot = "yellow4";

files = readdir(dirName);

statsDirs = [];

for i = 1 : rows(files)
      index = strfind(files{i}, "_stats");
      if any(index) == 1
      	statsDirs = [statsDirs; files{i}];
      endif
endfor

printf("Found %d dirs with the statistics\n",  rows(statsDirs));

statsDir = [dirName, "/", statsDirs(1,:)];
statFile = strcat(statsDir, "/", robot, ".stats");

COLUMN_ATTACKING = 6;
COLUMN_BALL_IN = 7;
COLUMN_SHOTS_COUNT = 12;
COLUMN_SUCCESSFUL_PASS = 13;
COLUMN_SUCCESSFUL_CAPTURE = 14;

x = [];
y = [];

for i = 1 : rows(statsDirs)
     printf(".");
     statsDir = [dirName, "/", statsDirs(i,:)];
     statFile = strcat(statsDir, "/", robot, ".stats");
     
     rawData = load ('-ascii',statFile);
     ballInData = rawData(find(rawData(:,COLUMN_BALL_IN) > 0), :);

     x = [x;ballInData(: , 1)];
     y = [y;ballInData(: , 2)];
     
endfor

%exp_nr = 5
%
%statsDir = [dirName, "/", statsDirs(exp_nr,:)];
%statFile = strcat(statsDir, "/", robot, ".stats");
%
%rawData = load ('-ascii',statFile);
%ballInData = rawData(find(rawData(:,COLUMN_BALL_IN) > 0), :);
%
%x = [ballInData(: , 1)];
%y = [ballInData(: , 2)];

x_bins = 0:0.2:5.4;
y_bins = 0:0.2:7.4;

subplot(1,2,1)
hist(x,x_bins)
xlabel("x",'FontName','Tahoma', 'fontsize',32)
axis([0 5.4],'square')
h = findobj(gca,'Type','patch');
r = 138; g = 59; b = 255;
set(h,'FaceColor',[r/255,g/255,b/255],'EdgeColor','k')
set (gca,'FontSize',32,'FontName','Tahoma')

subplot(1,2,2)
hist(y,y_bins)
xlabel('y','FontName','Tahoma', 'fontsize',32)
axis([0 7.4], 'square')
h = findobj(gca,'Type','patch');
r = 138; g = 59; b = 255;
set(h,'FaceColor',[r/255,g/255,b/255],'EdgeColor','k')
set (gca,'FontSize',32,'FontName','Tahoma')

print('-depsc','positionsHistogram.eps')
system('epstopdf positionsHistogram.eps')
system('pdfcrop positionsHistogram.pdf positionsHistogram.pdf')

%for i = 1 : rows(statsDirs)
%     printf(".");
%      statsDir = [dirName, "/", statsDirs(i,:)];
%      statFile = strcat(statsDir, "/", robotName ".stats");
      
      %yellowStatsSingleExp = [0 0 0];
   %   for j = 1 : rows(yellowStatFiles)
%     	yellowStatsSingleExp += countStats(yellowStatFiles(j,:));
%     endfor

%endfor

